package com.lty.jeeg.server.modules.fas.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.*;

import org.springframework.stereotype.Repository;

import com.lty.jeeg.server.modules.fas.model.OrderDetail;

/**
 * @author : zl
 * @date : 2019-02-17 09:18:28
 * Description : 采购明细
 */
@Mapper
@Repository
public interface OrderDetailDao {

    /**
     * 根据ID获取
     * @param id ID
     * @return bean
     */
    @Select("select * from fas_order_detail t where t.id = #{id}")
    OrderDetail getById(Long id);

    @Select("select * from fas_order_detail t where t.orderId = #{orderId}")
    List<OrderDetail> getByorderId(Long orderId);

    /**
     * 删除
     * @param id ID
     * @return 1/0
     */
    @Delete("delete from fas_order_detail where id = #{id}")
    int delete(Long id);

    /**
     * 修改
     * @param orderDetail ID
     * @return 1/0
     */
    int update(OrderDetail orderDetail);

    /**
     * 保存
     * @param orderDetail bean
     * @return ID
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into fas_order_detail(name, orderId, originatorId, originatorName, originatorOfficeId, originatorOfficeName, companyId, detailName, detailSpec, detailNum, detailUnit, detailSinprice, detailTolprice, createBy, updateBy, remark, isDeleted, orderType, handleType, buyStatus, actNum, goodsId, goodsName, supplierId, supplierName, detailTotalPrice, orderDetailType, delivererId, delivererName, waitNum, demandType) values(#{name}, #{orderId}, #{originatorId}, #{originatorName}, #{originatorOfficeId}, #{originatorOfficeName}, #{companyId}, #{detailName}, #{detailSpec}, #{detailNum}, #{detailUnit}, #{detailSinprice}, #{detailTolprice}, #{createBy}, #{updateBy}, #{remark}, #{isDeleted}, #{orderType}, #{handleType}, #{buyStatus}, #{actNum}, #{goodsId}, #{goodsName}, #{supplierId}, #{supplierName}, #{detailTotalPrice}, #{orderDetailType}, #{delivererId}, #{delivererName}, #{waitNum}, #{demandType})")
    Long save(OrderDetail orderDetail);

    /**
     * 计数
     * @param params 筛选条件
     * @return 总数
     */
    int count(@Param("params") Map<String, Object> params);

    /**
     * 列表
     * @param params 筛选条件
     * @param offset 页码
     * @param limit 分页数目
     * @return beanList
     */
    List<OrderDetail> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    /**
     * 修改订单明细里的订单状态
     * @param id
     * @param type
     * @return
     */
    @Update("UPDATE fas_order_detail t SET t.orderDetailType=#{type} WHERE t.orderId=#{id}")
    @ResultType(int.class)
    int changeType(@Param("id")Long id,@Param("type")String type);

    /**
     * 获取订单下的订单详细列表
     * @return
     */
    @Select("select t.* from fas_order_detail t where t.isDeleted=0 and t.orderId=#{orderId}")
    @ResultType(OrderDetail.class)
    List<OrderDetail> findOrderDetailListByOrderId(@Param("orderId")Long orderId);
}
